<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="客户分类" prop="customerClassify">
        <el-select v-model="queryParams.customerClassify" placeholder="请选择客户分类" class="w100" >
          <el-option
            v-for="dict in dict.type.zxcrm_customer_classify"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zxcrm:customer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['zxcrm:customer:remove']"
        >删除</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zxcrm:customer:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="customerList" @selection-change="handleSelectionChange"  @row-click="handleRowClick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司名称" align="center" prop="companyName" fixed min-width="150px"/>
      <el-table-column label="客户分类" align="center" prop="customerClassify" min-width="100px">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_customer_classify" :value="scope.row.customerClassify"/>
        </template>
      </el-table-column>
      <el-table-column label="信息完整度" align="center" prop="informationCompleteness" width="120px">
        <template slot-scope="scope" >
          <el-progress :percentage="Number(scope.row.informationCompleteness)" color="#F25847"></el-progress>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="customerStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.customerStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="是否成交" align="center" prop="dealStatus" />
      <el-table-column label="最后联系" align="center" prop="nextContactTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.nextContactTime, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后跟进" align="center" prop="finallyFollow" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finallyFollow, '{y}-{m}-{d} {h}:{m}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="录入方式" align="center" prop="inputMethod" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_input_method" :value="scope.row.inputMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="公司简称" align="center" prop="companyAbbreviation" />

      <el-table-column label="客户等级" align="center" prop="customerLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_customer_level" :value="scope.row.customerLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="经营地址" align="center" prop="operateAddress" />
      <el-table-column label="实际控制人" align="center" prop="actualControllerId" >
        <template slot-scope="scope">
          {{contactMap[scope.row.actualControllerId]}}
        </template>
      </el-table-column>
      <el-table-column label="疫苗部门负责人" align="center" prop="vaccineDepartmentHeadId" >
        <template slot-scope="scope">
          {{contactMap[scope.row.vaccineDepartmentHeadId]}}
        </template>
      </el-table-column>
      <el-table-column label="采购对接人" align="center" prop="purchaseDockingId" >
        <template slot-scope="scope">
          {{contactMap[scope.row.purchaseDockingId]}}
        </template>
      </el-table-column>
      <el-table-column label="库管" align="center" prop="warehouseOperatorId" >
        <template slot-scope="scope">
          {{contactMap[scope.row.warehouseOperatorId]}}
        </template>
      </el-table-column>
      <el-table-column label="使用者" align="center" prop="userId" >
        <template slot-scope="scope">
          {{contactMap[scope.row.userId]}}
        </template>
      </el-table-column>
      <el-table-column label="财务" align="center" prop="financeId" >
        <template slot-scope="scope">
            {{contactMap[scope.row.financeId]}}
          </template>
      </el-table-column>
      <el-table-column label="所属地区" align="center" prop="area" />
      <el-table-column label="客户类型" align="center" prop="customerType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_customer_type" :value="scope.row.customerType"/>
        </template>
      </el-table-column>
      <el-table-column label="竞品" align="center" prop="competitor" >
        <template slot-scope="scope">
           <div v-html="scope.row.competitor"></div>
        </template>
      </el-table-column>
      <el-table-column label="主销产品" align="center" prop="mainSalesProduct" show-overflow-tooltip>
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_main_sales_product" :value="scope.row.mainSalesProduct"/>
        </template>
      </el-table-column>
      <el-table-column label="客户关系" align="center" prop="customerReloationship">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_customer_relationship" :value="scope.row.customerReloationship"/>
        </template>
      </el-table-column>
      <el-table-column label="客户内部组织关系" align="center" prop="customerOrganizationalRelationship" />
      <el-table-column label="其他" align="center" prop="other" />
      <el-table-column label="接种量" align="center" prop="inoculationAmount" />
      <el-table-column label="采购负责人" align="center" prop="purchaseHeadId" >
        <template slot-scope="scope">
            {{contactMap[scope.row.purchaseHeadId]}}
        </template>
      </el-table-column>
      <el-table-column label="客户来源" align="center" prop="customerSource">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_customer_source" :value="scope.row.customerSource"/>
        </template>
      </el-table-column>
      <el-table-column label="客户成交卡点分析" align="center" prop="customerTransationAnalysis" />
      <el-table-column label="特殊要求" align="center" prop="specialRequirement" />
      <el-table-column label="回款周期" align="center" prop="paymentCycle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_payment_cycle" :value="scope.row.paymentCycle"/>
        </template>
      </el-table-column>
      <el-table-column label="结算方式" align="center" prop="medicinePaymentMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_medicine_payment_method" :value="scope.row.medicinePaymentMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="仓储配送" align="center" prop="warehouseDelivery" />
      <el-table-column label="供应商简称" align="center" prop="supplierAbbreviation" />
      <el-table-column label="销售负责人" align="center" prop="saleHeadId" >
        <template slot-scope="scope">
            {{contactMap[scope.row.saleHeadId]}}
        </template>
      </el-table-column>
      <el-table-column label="销售对接人" align="center" prop="saleContactId" >
        <template slot-scope="scope">
            {{contactMap[scope.row.saleContactId]}}
        </template>
      </el-table-column>
      <el-table-column label="供应商状态" align="center" prop="supplierStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_supplier_status" :value="scope.row.supplierStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="供应商来源" align="center" prop="supplierSource">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_supplier_source" :value="scope.row.supplierSource"/>
        </template>
      </el-table-column>
      <el-table-column label="供应商类型" align="center" prop="supplierType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_supplier_type" :value="scope.row.supplierType"/>
        </template>
      </el-table-column>
      <el-table-column label="供应商等级" align="center" prop="supplierLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_supplier_level" :value="scope.row.supplierLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="供应商内部组织关系" align="center" prop="supplierOrganizationalRelationship" />
      <el-table-column label="供应商政策支持" align="center" prop="supplierPolicySupport" />
      <el-table-column label="贷款周期" align="center" prop="loanCycle" />
      <el-table-column label="结算方式" align="center" prop="supplierPaymentMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zxcrm_supplier_payment_method" :value="scope.row.supplierPaymentMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="成交时间" align="center" prop="dealTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dealTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click.stop="handleUpdate(scope.row)"
            v-hasPermi="['zxcrm:customer:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click.stop="handleDelete(scope.row)"
            v-hasPermi="['zxcrm:customer:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改客户对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px"  append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="80px">
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户分类" prop="customerClassify">
              <el-select v-model="form.customerClassify" placeholder="请选择客户分类" class="w100" >
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_classify"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公司名称" prop="companyName" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <el-input v-model="form.companyName" placeholder="请输入公司名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户简称" prop="companyAbbreviation" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-input v-model="form.companyAbbreviation" placeholder="请输入公司简称" />
            </el-form-item>
            <el-form-item label="供应商简称" prop="supplierAbbreviation" v-if="form.customerClassify == 3 ">
              <el-input v-model="form.supplierAbbreviation" placeholder="请输入供应商简称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户等级" prop="customerLevel" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-select v-model="form.customerLevel" placeholder="请选择客户等级" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="供应商类型" prop="supplierType" v-if="form.customerClassify == 3">
              <el-select v-model="form.supplierType" placeholder="请选择供应商类型" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_supplier_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="经营地址" prop="operateAddress" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <el-input v-model="form.operateAddress" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="实际控制人" prop="actualControllerId" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <el-select v-model="form.actualControllerId" placeholder="请选择实际控制人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="疫苗部门负责人" prop="vaccineDepartmentHeadId" v-if="form.customerClassify == 1">
              <el-select v-model="form.vaccineDepartmentHeadId" placeholder="请选择疫苗部门负责人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="采购负责人" prop="purchaseHeadId" v-if="form.customerClassify == 2">
              <el-select v-model="form.purchaseHeadId" placeholder="请选择采购负责人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="采购对接人" prop="purchaseDockingId" v-if="form.customerClassify == 1 || form.customerClassify == 2 ">
              <el-select v-model="form.purchaseDockingId" placeholder="请选择采购对接人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="财务" prop="financeId" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <el-select v-model="form.financeId" placeholder="请选择财务" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属地区" prop="area" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-input v-model="form.area" placeholder="请输入所属地区" />
            </el-form-item>
            <el-form-item label="供应商来源" prop="supplierSource " v-if="form.customerClassify == 3">
              <el-select v-model="form.supplierSource" placeholder="请选择供应商来源" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_supplier_source"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户类型" prop="customerType" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-select v-model="form.customerType" placeholder="请选择客户类型" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="供应商状态" prop="supplierStatus" v-if="form.customerClassify == 3">
              <el-select v-model="form.supplierStatus" placeholder="请选择供应商状态" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_supplier_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="主销产品(疫苗)" prop="mainSalesProductVaccine" v-if="form.customerClassify == 1 ">
              <el-select v-model="mainSalesProduct" multiple placeholder="请选择主销产品" @change="handleMainSalesProduct" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_main_sales_product"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="主销产品" prop="mainSalesProduct" v-if=" form.customerClassify == 2 || form.customerClassify == 3">
               <el-input v-model="form.mainSalesProduct" type="textarea" placeholder="请输入主销产品" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="库管" prop="warehouseOperatorId" v-if="form.customerClassify == 1">
              <el-select v-model="form.warehouseOperatorId" placeholder="请选择库管" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="使用者" prop="userId" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-select v-model="form.userId" placeholder="请选择使用者" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="24">
            <el-form-item label="竞品" prop="competitor" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <editor v-model="form.competitor" :min-height="192"  />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户关系" prop="customerReloationship" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-select v-model="form.customerReloationship" placeholder="请选择客户关系" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_relationship"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户内部组织关系" prop="customerOrganizationalRelationship" v-if="form.customerClassify == 1 || form.customerClassify == 2">
              <el-input v-model="form.customerOrganizationalRelationship" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户状态" prop="customerStatus" v-if="form.customerClassify == 2">
              <el-select v-model="form.customerStatus" placeholder="请选择客户状态" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="客户来源" prop="customerSource" v-if="form.customerClassify == 2">
              <el-select v-model="form.customerSource" placeholder="请选择客户来源" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_customer_source"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="客户成交卡点分析" prop="customerTransationAnalysis" v-if="form.customerClassify == 2">
              <el-input v-model="form.customerTransationAnalysis" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="供应商政策支持" prop="supplierPolicySupport" v-if="form.customerClassify == 3">
              <el-input v-model="form.supplierPolicySupport" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="特殊要求或条件" prop="specialRequirement" v-if="form.customerClassify == 2 || form.customerClassify == 3">
              <el-input v-model="form.specialRequirement" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="回款周期" prop="paymentCycle" v-if="form.customerClassify == 2">
              <el-select v-model="form.paymentCycle" placeholder="请选择回款周期" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_payment_cycle"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结算方式(药品)" prop="medicinePaymentMethod" v-if="form.customerClassify == 2">
              <el-select v-model="form.medicinePaymentMethod" placeholder="请选择结算方式(药品)" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_medicine_payment_method"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="销售对接人" prop="saleContactId" v-if="form.customerClassify == 3">
              <el-select v-model="form.saleContactId" placeholder="请选择销售对接人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="销售负责人" prop="saleHeadId" v-if="form.customerClassify == 3">
              <el-select v-model="form.saleHeadId" placeholder="请选择销售负责人" class="w100" filterable>
                <el-option
                  v-for="item in contactList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                  <div class="flex-space-between">
                    <span>{{ item.name }}</span>
                    <span class="font-gray">{{ item.customerCompanyName }}</span>
                  </div>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="供应商等级" prop="supplierLevel" v-if="form.customerClassify == 3">
              <el-select v-model="form.supplierLevel" placeholder="请选择供应商等级" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_supplier_level"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="供应商内部组织关系" prop="supplierOrganizationalRelationship" v-if="form.customerClassify == 3">
              <el-input v-model="form.supplierOrganizationalRelationship" placeholder="请输入供应商内部组织关系" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="贷款周期" prop="loanCycle" v-if="form.customerClassify == 3">
              <el-input v-model="form.loanCycle" placeholder="请输入贷款周期" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结算方式(供应商)" prop="supplierPaymentMethod" v-if="form.customerClassify == 3">
              <el-select v-model="form.supplierPaymentMethod" placeholder="请选择结算方式(供应商)" class="w100">
                <el-option
                  v-for="dict in dict.type.zxcrm_supplier_payment_method"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="gutter">
          <el-col :span="12">
            <el-form-item label="其他" prop="other" v-if="form.customerClassify == 1 || form.customerClassify == 2 || form.customerClassify == 3">
              <el-input v-model="form.other" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="仓储配送" prop="warehouseDelivery" v-if="form.customerClassify == 2 || form.customerClassify == 3">
              <el-input v-model="form.warehouseDelivery" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <el-form-item label="接种量" prop="inoculationAmount" v-if="form.customerClassify == 1">
              <el-input v-model="form.inoculationAmount" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/zxcrm/customer"
import { listAllContact} from "@/api/zxcrm/contact"
export default {
  name: "Customer",
  dicts: ['zxcrm_customer_classify', 'zxcrm_customer_level', 'zxcrm_supplier_status', 'zxcrm_payment_cycle', 'zxcrm_supplier_payment_method', 'zxcrm_customer_relationship', 'zxcrm_main_sales_product', 'zxcrm_medicine_payment_method', 'zxcrm_supplier_type', 'zxcrm_customer_status', 'zxcrm_customer_type', 'zxcrm_supplier_level', 'zxcrm_customer_source', 'zxcrm_supplier_source','	zxcrm_input_method'],
  data() {
    return {
      contactList:[],
      contactMap:null,
      test:[
        {
          value: 'Beijing',
          label: '北京'
        }, {
          value: 'Shanghai',
          label: '上海'
        }
      ],
      gutter:20,
      mainSalesProduct:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 客户表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: null,
        companyAbbreviation: null,
        customerClassify: null,
        customerLevel: null,
        operateAddress: null,
        actualControllerId: null,
        vaccineDepartmentHeadId: null,
        purchaseDockingId: null,
        warehouseOperatorId: null,
        userId: null,
        financeId: null,
        area: null,
        customerType: null,
        competitor: null,
        mainSalesProduct: null,
        mainSalesProductVaccine: null,
        customerReloationship: null,
        customerOrganizationalRelationship: null,
        other: null,
        inoculationAmount: null,
        purchaseHeadId: null,
        customerStatus: null,
        customerSource: null,
        customerTransationAnalysis: null,
        specialRequirement: null,
        paymentCycle: null,
        medicinePaymentMethod: null,
        warehouseDelivery: null,
        supplierAbbreviation: null,
        saleHeadId: null,
        saleContactId: null,
        supplierStatus: null,
        supplierSource: null,
        supplierType: null,
        supplierLevel: null,
        supplierOrganizationalRelationship: null,
        supplierPolicySupport: null,
        loanCycle: null,
        supplierPaymentMethod: null,
        dealStatus: null,
        dealTime: null,
        nextContactTime: null,
        inputMethod: null,
        informationCompleteness: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
          companyName: [
            { required: true, message: '公司名称是必填项', trigger: 'blur' }
          ],
          customerLevel: [
            { required: true, message: '客户等级是必填项', trigger: 'blur' }
          ],
          customerType: [
            { required: true, message: '客户类型是必填项', trigger: 'blur' }
          ],
      }
    }
  },
  created() {
    this.getList()
    this.getContactList()
  },
  methods: {
    handleRowClick(row, column, event){
      this.$router.push({ path: "/zxcrm/customerInfo",query: {id: row.id} });
    },
    getContactList(){
      listAllContact().then(res=>{
        this.contactList = res.data
        this.contactMap = this.contactList.reduce((map,item)=>{
          map[item.id] = item.name
          return map
        },{})
      })
    },
    /** 处理主要销售产品改变 */
    handleMainSalesProduct(e){
      this.form.mainSalesProduct = e.join(",")
    },
    /** 查询客户列表 */
    getList() {
      this.loading = true
      listCustomer(this.queryParams).then(response => {
        this.customerList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.mainSalesProduct = []
      this.form = {
        id: null,
        companyName: null,
        companyAbbreviation: null,
        customerClassify: null,
        customerLevel: null,
        operateAddress: null,
        actualControllerId: null,
        vaccineDepartmentHeadId: null,
        purchaseDockingId: null,
        warehouseOperatorId: null,
        userId: null,
        financeId: null,
        area: null,
        customerType: null,
        competitor: null,
        mainSalesProduct: null,
        customerReloationship: null,
        customerOrganizationalRelationship: null,
        other: null,
        inoculationAmount: null,
        purchaseHeadId: null,
        customerStatus: null,
        customerSource: null,
        customerTransationAnalysis: null,
        specialRequirement: null,
        paymentCycle: null,
        medicinePaymentMethod: null,
        warehouseDelivery: null,
        supplierAbbreviation: null,
        saleHeadId: null,
        saleContactId: null,
        supplierStatus: null,
        supplierSource: null,
        supplierType: null,
        supplierLevel: null,
        supplierOrganizationalRelationship: null,
        supplierPolicySupport: null,
        loanCycle: null,
        supplierPaymentMethod: null,
        dealStatus: null,
        dealTime: null,
        nextContactTime: null,
        inputMethod: null,
        informationCompleteness: null,
        status: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加客户"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getCustomer(id).then(response => {
        this.form = response.data
        if(this.form.mainSalesProduct){
          this.mainSalesProduct = this.form.mainSalesProduct.split(",")
        }
        this.open = true
        this.title = "修改客户"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除客户编号为"' + ids + '"的数据项？').then(function() {
        return delCustomer(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zxcrm/customer/export', {
        ...this.queryParams
      }, `customer_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
